package com.ruoyi.project.system.customer.controller;

import java.util.List;

import com.ruoyi.project.system.student.domain.Student;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.customer.domain.VeCustomer;
import com.ruoyi.project.system.customer.service.IVeCustomerService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-01-06
 */
@Controller
@RequestMapping("/system/customer")
public class VeCustomerController extends BaseController
{
    private String prefix = "system/customer";

    @Autowired
    private IVeCustomerService veCustomerService;

    @RequiresPermissions("system:customer:view")
    @GetMapping()
    public String customer()
    {
        return prefix + "/customer";
    }

    @RequiresPermissions("system:customer:noauth")
    @GetMapping("/customernoauth")
    public String customernoauth()
    {
        return prefix + "/customernoauth";
    }

    @RequiresPermissions("system:customer:finish")
    @GetMapping("/customerfinish")
    public String customerfinish()
    {
        return prefix + "/customerfinish";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:customer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VeCustomer veCustomer)
    {
        startPage();
        List<VeCustomer> list = veCustomerService.selectVeCustomerList(veCustomer);
        return getDataTable(list);
    }

    @RequiresPermissions("system:customer:listnoauth")
    @PostMapping("/listnoauth")
    @ResponseBody
    public TableDataInfo listnoauth(VeCustomer veCustomer)
    {
        startPage();
        List<VeCustomer> list = veCustomerService.noFinishTask(getUserId(),"travelrequest");
        return getDataTable(list);
    }

    @RequiresPermissions("system:customer:listfinish")
    @PostMapping("/listfinish")
    @ResponseBody
    public TableDataInfo listfinish(VeCustomer veCustomer)
    {
        startPage();
        List<VeCustomer> list = veCustomerService.finishTask(getUserId(),"travelrequest");
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:customer:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VeCustomer veCustomer)
    {
        List<VeCustomer> list = veCustomerService.selectVeCustomerList(veCustomer);
        ExcelUtil<VeCustomer> util = new ExcelUtil<VeCustomer>(VeCustomer.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:customer:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VeCustomer veCustomer)
    {
        return toAjax(veCustomerService.insertVeCustomer(veCustomer));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("system:customer:edit")
    @GetMapping("/edit/{CustomerID}")
    public String edit(@PathVariable("CustomerID") Long CustomerID, ModelMap mmap)
    {
        VeCustomer veCustomer = veCustomerService.selectVeCustomerByCustomerID(CustomerID);
        mmap.put("veCustomer", veCustomer);
        return prefix + "/edit";
    }

    @RequiresPermissions("system:customer:editnoauth")
    @GetMapping("/editnoauth/{CustomerID}")
    public String editnoauth(@PathVariable("CustomerID") Long CustomerID, ModelMap mmap)
    {
        VeCustomer veCustomer = veCustomerService.selectVeCustomerByCustomerID(CustomerID);
        mmap.put("veCustomer", veCustomer);
        mmap.put("taskCommentVoList",veCustomerService.getTaskCommentList(veCustomer.getFlowInstanceId()));
        return prefix + "/editnoauth";
    }

    @RequiresPermissions("system:customer:editfinish")
    @GetMapping("/editfinish/{CustomerID}")
    public String editfinish(@PathVariable("CustomerID") Long CustomerID, ModelMap mmap)
    {
        VeCustomer veCustomer = veCustomerService.selectVeCustomerByCustomerID(CustomerID);
        mmap.put("veCustomer", veCustomer);
        mmap.put("taskCommentVoList",veCustomerService.getTaskCommentList(veCustomer.getFlowInstanceId()));
        return prefix + "/editfinish";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:customer:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VeCustomer veCustomer)
    {
        return toAjax(veCustomerService.updateVeCustomer(veCustomer));
    }

    @RequiresPermissions("system:customer:editnoauth")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/editnoauthdata")
    @ResponseBody
    public AjaxResult editSaveNoauthData(VeCustomer veCustomer)
    {
        veCustomerService.completeTask(veCustomer.getFlowInstanceId(),veCustomer.getAgree(),getUserId(),veCustomer.getComment(),veCustomer.getCustomerID());
        return toAjax(200);
    }

    @RequiresPermissions("system:customer:editfinish")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/editfinishdata")
    @ResponseBody
    public AjaxResult editSaveFinishData(VeCustomer veCustomer)
    {
        veCustomerService.completeTask(veCustomer.getFlowInstanceId(),veCustomer.getAgree(),getUserId(),veCustomer.getComment(),veCustomer.getCustomerID());
        return toAjax(200);
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:customer:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(veCustomerService.deleteVeCustomerByCustomerIDs(ids));
    }

    @PostMapping( "/deploy")
    @ResponseBody
    public AjaxResult deploy(Long id,Long userId)
    {
        return toAjax(veCustomerService.submit(id,getUserId()));
    }

}
